package com.lpit.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lpit.constant.Constant;
import com.lpit.dto.CertificationDto;
import com.lpit.pojo.Certification;
import com.lpit.service.CertificationService;
import com.lpit.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/admin")
public class CertificationController {

    @Autowired
    private CertificationService certificationService;


    /*查看审核资料*/
    @GetMapping("/userAuditData.html")
    public Result<Certification> lookAuditData(Integer id){
        return Result.success(certificationService.getById(id));
    }

    /*查看审核用户列表*/
    @GetMapping("/userAuditList.html/{page}/{pageSize}")
    public Result<IPage<CertificationDto>> lookAuditList(@PathVariable Integer page,@PathVariable Integer pageSize){

        return Result.success(certificationService.lookCertificationList(page,pageSize));
    }

    /*批量通过审核*/
    @PutMapping("/batchPass.html")
    public Result<String> batchPass(@RequestParam("id") List<Integer> integers, HttpServletRequest hsr){
        /*
         * integers 认证表的id集合
         * hsr.getRequestURI() ：请求路径
         * */
        return certificationService.updateCertificationStatus(integers, hsr.getRequestURI()) ? Result.success(Constant.MESSAGE_OPERATION_SUCCEED) : Result.error(Constant.MESSAGE_OPERATION_FAIL);
    }

    /*批量驳回审核*/
    @PutMapping("/batchReject.html")
    public Result<String> batchReject(@RequestParam("id") List<Integer> integers, HttpServletRequest hsr){
        /*
         * integers 认证表的id集合
         * hsr.getRequestURI() ：请求路径
         * */
        return certificationService.updateCertificationStatus(integers, hsr.getRequestURI()) ? Result.success(Constant.MESSAGE_OPERATION_SUCCEED) : Result.error(Constant.MESSAGE_OPERATION_FAIL);
    }
}
